/*************************************************
 * 描述：侧边栏私有实现类
 *
 * File：cxisidebarmenu_p.h
 * Author：zhangzhiming@mozihealthcare.cn
 * Date：25-9-23
 * Update：
 * ************************************************/

#ifndef CXISIDEBARMENUPRIVATE_H
#define CXISIDEBARMENUPRIVATE_H
#include <QPainter>
#include <QStyledItemDelegate>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <controls/menu/cxisidebarmenu.h>

class FullRowDelegate : public QStyledItemDelegate {
public:
	using QStyledItemDelegate::QStyledItemDelegate;
	void paint(QPainter *painter,
			   const QStyleOptionViewItem &option,
			   const QModelIndex &index) const override
	{
		QStyleOptionViewItem opt = option;
		initStyleOption(&opt, index);

		// 用 const QTreeView* 而不是 非 const
		const QTreeView *tree = qobject_cast<const QTreeView *>(opt.widget);
		if (tree && (opt.state & QStyle::State_Selected)) {
			QRect fullRect = opt.rect;
			fullRect.setX(0);
			fullRect.setWidth(tree->viewport()->width());
			painter->fillRect(fullRect, opt.palette.highlight());
			painter->setPen(opt.palette.highlightedText().color());
		}
		opt.state &= ~QStyle::State_HasFocus;
		opt.state &= ~QStyle::State_KeyboardFocusChange;
		// QStyledItemDelegate::paint(painter, option, index);
	}

};

class CxiSideBarMenuPrivate
{
	Q_DISABLE_COPY(CxiSideBarMenuPrivate)
	Q_DECLARE_PUBLIC(CxiSideBarMenu)
public:
	explicit CxiSideBarMenuPrivate(CxiSideBarMenu* q);
	~CxiSideBarMenuPrivate();

	CxiSideBarMenu* q_ptr;

private:
	void init();
	QVBoxLayout* m_mainLayout;
	QTreeWidget* m_treeWidget;
};


#endif//CXISIDEBARMENUPRIVATE_H
